package edu.sctu.zcy.month201505.day20150521;

/**
 * Created by wswk on 2015/5/21.
 */
public class ThreadDemo extends Thread{

    public void run(){

        System.out.println(getName()+"  线程开始");
        int count= 0;

        boolean key = true;

        while (key){

            System.out.println(getName()+(++count));
            if(count == 100){
                key = false;

            }

            if(count%10 == 0){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }

        System.out.println(getName()+"  线程结束！");

    }



    public static void main(String[] args) {

        Thread thread = new ThreadDemo();

        thread.setName("Mr.Thread");
        thread.start();

        Thread thread1 = new Thread(new RunnableDemo(),"Mis.Runnable");
        thread1.start();
    }
}

class RunnableDemo implements Runnable{


    @Override
    public void run(){

        System.out.println(Thread.currentThread().getName()+"  线程开始");

        int count= 0;

        boolean key = true;

        while (key){

            System.out.println(Thread.currentThread().getName()+(++count));
            if(count == 100){
                key = false;

            }

            if(count%10 == 0){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }

        System.out.println(Thread.currentThread().getName()+"  线程结束！");

    }
}